<include file="_header" />
<div class="so_main">
  <include file="_tab" />

  <div id="search_div" <neq name="isSearch" value="1">style="display:none;"</neq>>
    <div class="page_tit">搜索附件 [ <a href="javascript:void(0);" onclick="searchAttach();">隐藏</a> ]</div>
    <div class="form2">
    <form method="post" action="{:U('weibo/Admin/fileList')}">
    <input type="hidden" name="isSearch" value="1"/>
    <dl class="lineD">
      <dt>ID：</dt>
      <dd><input name="id" type="text" value="{$id}"><p>多个时使用英文的“,”分割</p></dd>
    </dl>
    
    <dl class="lineD">
      <dt>用户ID：</dt>
      <dd>
        <input name="userId" type="text" value="{$userId}">
        <p>用户ID,多个时使用英文的","分割</p>
      </dd>
    </dl>
    
    <dl class="lineD">
      <dt>扩展名：</dt>
      <dd>
        <select name="extension">
            <option value="" selected> - </option>
            <volist name="extensions" id="vo">
            <option value="{$vo}" <php>if($vo==$extension) echo 'selected';</php>>{$vo}</option>
            </volist>
        </select>
      </dd>
    </dl>
    <div class="page_btm">
      <input type="submit" class="btn_b" value="确定" />
    </div>
    </form>
  </div>
  </div>

  <div class="Toolbar_inbox">
    <div class="page right">{$html}</div>
    <a href="javascript:void(0);" class="btn_a" onclick="searchAttach();">
        <span class="search_action"><neq name="isSearch" value="1">搜索附件<else/>搜索完毕</neq></span>
    </a>
    <a href="javascript:void(0);" class="btn_a" onclick="deleteFile();"><span>删除记录</span></a>
  </div>
  <div class="list">
  <table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <th style="width:30px;">
        <input type="checkbox" id="checkbox_handle" onclick="checkAll(this)" value="0">
        <label for="checkbox"></label>
    </th>
    <th class="line_l">ID</th>
    <th class="line_l">UID</th>
    <th class="line_l">用户名</th>
    <th class="line_l">附件类型</th>
    <th class="line_l">附件名称</th>
    <th class="line_l">附件大小</th>
    <th class="line_l">扩展名</th>
    <th class="line_l">上传时间</th>
    <th class="line_l">操作</th>
  </tr>
  <volist id="vo" name="data">
      <tr overstyle='on' id="attach_{$vo['id']}">
        <td><input type="checkbox" name="checkbox" id="checkbox2" onclick="checkon(this)" value="{$vo.id}"></td>
        <td>{$vo.id}</td>
        <td>{$vo.userId}</td>
        <td>{$vo.userId|getUserName}</td>
        <td>{$vo.attach_type}</td>
        <td><a href="data/uploads/{$vo.savepath}{$vo.savename}" target="_blank">{$vo.name}</a></td>
        <php>$vo['size'] = round($vo['size']/1000,2);</php>
        <td>{$vo.size} K</td>
        <td>{$vo.extension}</td>
        <td>{$vo.uploadTime|date="Y-m-d H:i",###}</td>
        <td>
        	<if condition="$vo['weibo_id']">
        	  <a href="{:U('home/Space/detail', array('id'=>$vo['weibo_id']))}" target="_blank">[查看微博]</a>
        	<else />
        	  [查看微博]
        	</if>
            <a href="javascript:void(0);" onclick="deleteFile('{$vo.id}')">删除记录</a>
        </td>
      </tr>
  </volist>
  </table>
  </div>
  <div class="Toolbar_inbox">
    <div class="page right">{$html}</div>
    <a href="javascript:void(0);" class="btn_a" onclick="searchAttach();">
        <span class="search_action"><neq name="isSearch" value="1">搜索附件<else/>搜索完毕</neq></span>
    </a>
    <a href="javascript:void(0);" class="btn_a" onclick="deleteFile();"><span>[删除记录]</span></a>
  </div>
</div>

<script>
    //鼠标移动表格效果
    $(document).ready(function(){
        $("tr[overstyle='on']").hover(
          function () {
            $(this).addClass("bg_hover");
          },
          function () {
            $(this).removeClass("bg_hover");
          }
        );
    });
    
    function checkon(o){
        if( o.checked == true ){
            $(o).parents('tr').addClass('bg_on') ;
        }else{
            $(o).parents('tr').removeClass('bg_on') ;
        }
    }
    
    function checkAll(o){
        if( o.checked == true ){
            $('input[name="checkbox"]').attr('checked','true');
            $('tr[overstyle="on"]').addClass("bg_on");
        }else{
            $('input[name="checkbox"]').removeAttr('checked');
            $('tr[overstyle="on"]').removeClass("bg_on");
        }
    }

    //获取已选择用户的ID数组
    function getChecked() {
        var ids = new Array();
        $.each($('table input:checked'), function(i, n){
            ids.push( $(n).val() );
        });
        return ids;
    }
    
    function deleteRecord(ids) {
    	var length = 0;
    	if(ids) {
    		length = 1;    		
    	}else {
    		ids    = getChecked();
    		length = ids.length;
            ids    = ids.toString();
    	}
    	
    	if(ids=='') {
    		ui.error('请先选择一个附件');
    		return ;
    	}
    	if(confirm('您将删除'+length+'条记录，删除后无法恢复，确定继续？')) {
    		$.post("{:U('admin/Content/doDeleteAttach')}",{ids:ids,withfile:0},function(res){
    			if(res=='1') {
    				ui.success('删除成功');
    				removeItem(ids);
    			}else {
    				ui.error('删除失败');
    			}
    		});
    	}
    }
    
    function deleteFile(ids) {
        var length = 0;
    	if(ids) {
            length = 1;         
        }else {
            ids    = getChecked();
            length = ids.length;
            ids    = ids.toString();
        }
        if(ids=='') {
            ui.error('请先选择一个附件');
            return ;
        }
        if(confirm('您将删除'+length+'条记录及其文件，删除后无法恢复，确定继续？')) {
            $.post("{:U('admin/Content/doDeleteAttach')}",{ids:ids,withfile:1},function(res){
                if(res=='1') {
                    ui.success('删除成功');
                    removeItem(ids);
                }else {
                    ui.error('删除失败');
                }
            });
        }
    }
    
    function removeItem(ids) {
    	ids = ids.split(',');
        for(i = 0; i < ids.length; i++) {
            $('#attach_'+ids[i]).remove();
        }
    }
    
    //搜索用户
    var isSearchHidden = <neq name="isSearch" value="1">1<else/>0</neq>;
    function searchAttach() {
        if(isSearchHidden == 1) {
            $("#search_div").slideDown("fast");
            $(".search_action").html("搜索完毕");
            isSearchHidden = 0;
        }else {
            $("#search_div").slideUp("fast");
            $(".search_action").html("搜索附件");
            isSearchHidden = 1;
        }
    }
</script>

<include file="_footer" />